package com.fwc.fw.domo;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
@Inheritance(strategy=InheritanceStrategy.SUBCLASS_TABLE)
public class AbstractPersistableDomo extends AbstractDomo implements Comparable {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	private String key;
	
    @Persistent
    private Date createdDate = new Date();

    @Persistent
    private String createdBy;

    @Persistent
    private Date modifiedDate = new Date();

    @Persistent
    private String modifiedBy;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

	public Date getCreatedDate() {
		return createdDate;
	}

	/*
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	*/

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public String getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	@Override
	public int compareTo(Object o) {
		if(o.getClass().equals(this.getClass()) && this.getKey().equals(((AbstractPersistableDomo)o).getKey())) return 0;
		else return 1;
	}

	//for freemarker and other OGNL uses
	public String getString() {
		return this.toString();
	}

}
